package com.sample.library.portlet.search.author;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.portlet.PortletRequest;
import javax.portlet.PortletURL;

import com.liferay.portal.kernel.dao.search.SearchContainer;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.ParamUtil;
import com.sample.library.model.Author;

public class AuthorSearch extends SearchContainer<Author> {
	static List<String> headerNames = new ArrayList<String>();
	static Map<String, String> orderableHeaders = new HashMap<String, String>();

	public static final String EMPTY_RESULTS_MESSAGE = "no-users-were-found";

	public AuthorSearch(PortletRequest portletRequest, PortletURL iteratorURL) {
		this(portletRequest, DEFAULT_CUR_PARAM, iteratorURL);
	}

	public AuthorSearch(PortletRequest portletRequest, String curParam,
			PortletURL iteratorURL) {

		super(portletRequest, new AuthorDisplayTerms(portletRequest),
				new AuthorSearchTerms(portletRequest), curParam, DEFAULT_DELTA,
				iteratorURL, headerNames, EMPTY_RESULTS_MESSAGE);

		AuthorDisplayTerms displayTerms = (AuthorDisplayTerms) getDisplayTerms();

		iteratorURL.setParameter(AuthorDisplayTerms.NAME, displayTerms.getName());
		iteratorURL.setParameter(AuthorDisplayTerms.EMAIL, displayTerms.getEmail());

		try {
			//
			String orderByCol = ParamUtil.getString(portletRequest, "orderByCol");
			String orderByType = ParamUtil.getString(portletRequest, "orderByType");

			OrderByComparator orderByComparator = getAuthorOrderByComparator( orderByCol, orderByType);

			setOrderableHeaders(orderableHeaders);
			setOrderByCol(orderByCol);
			setOrderByType(orderByType);
			setOrderByComparator(orderByComparator);
		} catch (Exception e) {
			_log.error(e);
		}
	}

	private OrderByComparator getAuthorOrderByComparator(String orderByCol,
			String orderByType) {

		OrderByComparator orderByComparator = null;

		return orderByComparator;
	}

	private static Log _log = LogFactoryUtil.getLog(AuthorSearch.class);
}
